package com.ruoyi.user.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.user.domain.CheMessage;
import com.ruoyi.user.service.ICheMessageService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 消息表Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/message")
public class CheMessageController extends BaseController
{
    @Autowired
    private ICheMessageService cheMessageService;

    /**
     * 查询消息表列表
     */
    @RequiresPermissions("user:message:list")
    @GetMapping("/list")
    public TableDataInfo list(CheMessage cheMessage)
    {
        startPage();
        List<CheMessage> list = cheMessageService.selectCheMessageList(cheMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息表列表
     */
    @RequiresPermissions("user:message:export")
    @Log(title = "消息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheMessage cheMessage)
    {
        List<CheMessage> list = cheMessageService.selectCheMessageList(cheMessage);
        ExcelUtil<CheMessage> util = new ExcelUtil<CheMessage>(CheMessage.class);
        util.exportExcel(response, list, "消息表数据");
    }

    /**
     * 获取消息表详细信息
     */
    @RequiresPermissions("user:message:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cheMessageService.selectCheMessageById(id));
    }
    @RequiresPermissions("user:message:query")
    @GetMapping(value = "/aa/{id}")
    public List<CheMessage> getInfo1(@PathVariable("id") Long id)
    {
        return cheMessageService.selectCheMessageListByUserId(id);
    }

    /**
     * 新增消息表
     */
    @RequiresPermissions("user:message:add")
    @Log(title = "消息表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheMessage cheMessage)
    {
        return toAjax(cheMessageService.insertCheMessage(cheMessage));
    }

    /**
     * 修改消息表
     */
    @RequiresPermissions("user:message:edit")
    @Log(title = "消息表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheMessage cheMessage)
    {
        return toAjax(cheMessageService.updateCheMessage(cheMessage));
    }

    /**
     * 删除消息表
     */
    @RequiresPermissions("user:message:remove")
    @Log(title = "消息表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cheMessageService.deleteCheMessageByIds(ids));
    }
}
